<style lang="less" scoped>

</style>
<template>
    <div>
        <x-header  :left-options="{showBack: false}">用户中心</x-header>
        <div>
            <group>
                <cell title="用户名" :value="userInfo.username" @click.native="changeUserName"  is-link></cell>
                <cell title="账户" :value="userInfo.account" ></cell>
                <cell title="公司" :value="userInfo.company" ></cell>
            </group>
            <group>
                <cell title="退出" @click.native="sheetShow=true" ></cell>
            </group>
        </div>
        <actionsheet v-model="sheetShow" :menus="sheetMenu"  show-cancel @on-click-menu="menuChange"></actionsheet>

    </div>
</template>


<script>
    import { Actionsheet } from 'vux'
    export default{
        data(){
            return {
                userInfo:{},
                sheetShow:false,
                sheetMenu:{
                    logout:'退出'
                }
            }
        },
        components: {
            Actionsheet
        },
        computed: {},
        methods: {
            getUserInfo(){
                this.$store.dispatch('GetUserInfo').then((response) => {
                    if (response.status == 1) {
                        this.userInfo = response.result;
                    }else {
                        this.$vux.toast.text('失败', 'bottom');
                    }
                }).catch((err) => {
                    this.$vux.loading.hide()
                });
            },
            changeUserName(){

            },
            logout(){
                this.$store.dispatch('Logout').then((response) => {
                    if (response.status == 1) {
                        sessionStorage.clear();
                        location.reload();
                    }else {
                        this.$vux.toast.text('失败', 'bottom');
                    }
                }).catch((err) => {
                    this.$vux.loading.hide()
                });
            },
            menuChange(menuKey, menuItem){
                switch(menuKey){
                    case 'logout':
                        this.logout();
                        break;
                }
            }
        },
        created: function () {
            this.getUserInfo();
        }
    }
</script>
